<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<link rel="stylesheet" href="../js/bootstrap3/css/bootstrap.min.css">
<link rel="stylesheet" href="../js/bootstrap-table/bootstrap-table.min.css">
<link rel="stylesheet" href="../js/bootstrap-datetimepicker/css/bootstrap-datetimepicker.min.css">
<link rel="stylesheet" href="../js/bootstrap-dialog/dist/css/bootstrap-dialog.min.css">
<script type="text/javascript" src="../js/jquery-3.6.0.min.js"></script>
<script type="text/javascript" src="../js/bootstrap3/js/bootstrap.min.js"></script>
<script type="text/javascript" src="../js/bootstrap-table/bootstrap-table.min.js"></script>
<script type="text/javascript" src="../js/bootstrap-table/locale/bootstrap-table-zh-CN.js"></script>
<script type="text/javascript" src="../js/bootstrap-datetimepicker/js/bootstrap-datetimepicker.min.js"></script>
<script type="text/javascript" src="../js/bootstrap-datetimepicker/js/locales/bootstrap-datetimepicker.zh-CN.js"></script>
<script type="text/javascript" src="../js/bootstrap-bootbox/bootbox.js"></script>
<script type="text/javascript" src="../js/bootstrap-dialog/dist/js/bootstrap-dialog.min.js"></script>
<body>

<input type="hidden" id="queryId" th:value="${queryId}"/>
<div id="myTable"></div>

</body>
<script>

    $(function (){
        initTable();
    })

    function initTable(){

        $("#myTable").bootstrapTable({
            url:"../backstage/queryZixunList?queryId="+$("#queryId").val(),
            pagination: true,               //是否显示分页（*）
            pageNumber:1,                   //初始化加载第一页，默认第一页
            pageSize: 3,                    //每页的记录行数（*）
            pageList: [3, 5, 7, 9],         //可供选择的每页的行数（*）
            method: 'get',                  //访问请求方式  get post
            smartDisplay: false,            //设置显示分页列表
            sidePagination: "server",       // 表格分页的是客户端分页还是服务端分页  cilent/server
            showRefresh:true,			    //是否显示刷新按钮
            showToggle:true,			    //是否显示详细视图和列表视图的切换按钮
            queryParams:function(){

                return {
                    page:this.pageNumber,
                    rows:this.pageSize

                }
            },

            columns: [{
                checkbox:true
            },{
                field:"zixunid",
                title:"编号"
            },{
                field: "zixuntitle",
                title: "标题"
            },{
                field: "zixunimg",
                title: "封面",
                formatter:function (value, row, index){
                    return "<img src='"+value+"' height='50px'/>";
                }
            },{
                field: "zixunauthor",
                title: "作者"
            },{
                field: "zixundate",
                title: "上传日期"
            }, {
                field: "status",
                title: "操作",
                formatter:function(value,row,index){

                    if(value==1){
                        return '<input type="button" class="btn btn-sm btn-info" onClick="lookZixunContent('+row.zixunid+')" value="查看">'
                            +  '<input type="button"  class="btn btn-sm btn-danger" onclick="updateStauts('+row.zixunid+')" value="删除">'
                            +  '<input type="button"  class="btn btn-sm btn-danger" onclick="toUpdateZixun('+row.zixunid+')" value="修改">';
                    }
                    if(value==2){
                        return '<input type="button" class="btn btn-sm btn-info" onClick="lookZixunContent('+row.zixunid+')" value="查看">'
                            +  '<input type="button"  class="btn btn-sm btn-info" onclick="updateStauts('+row.zixunid+')" value="恢复">'
                            +  '<input type="button"  class="btn btn-sm btn-danger" onclick="deleteZixun('+row.zixunid+')" value="删除">';
                    }
                }
            }]
        })
    }

    //查看详情
    function lookZixunContent(zixunid){
        location.href="../backstage/lookZixunContent?zixunid="+zixunid;
    }

    //去修改
    function toUpdateZixun(zixunid){
        location.href="../backstage/toUpdateZixun?zixunid="+zixunid;
    }

    //删除状态
    function updateStauts(zixunid){
        $.ajax({
            url: "../backstage/updateZixunStatus?zixunid="+zixunid,
            type: "post",
            success:function (data){
                //alert("删除成功！");
                //location.href="../backstage/index";
                $("#myTable").bootstrapTable("refresh");
            },error:function(){
                alert("删除失败！");
            }
        })
    }

    //磁盘删除
    function deleteZixun(zixunid){
        $.ajax({
            url: "../backstage/deleteZixun?zixunid="+zixunid,
            type: "post",
            success:function (data){
                //alert("删除成功！");
                //location.href="../backstage/index";
                $("#myTable").bootstrapTable("refresh");
            },error:function(){
                alert("删除失败！");
            }
        })
    }


</script>
</html>